<template>
  <div class="post-collect">
    <h2>我的收藏</h2>
    <div class="topic-list">
      <div
          class="topic-item"
          v-for="topic in favorites"
          :key="topic.id"
          @click="goToTopicDetail(topic.id)"
      >
        <div class="topic-avatar">
          <img :src="topic.avatar" alt="avatar" />
        </div>
        <div class="topic-content">
          <div class="topic-info">
            <h3>{{ topic.title }}</h3>
            <p class="author-time">
              <span>{{ topic.author }}</span>
              <span>{{ formatTime(topic.timeAgo) }}</span>
            </p>
          </div>
          <p class="description">{{ topic.description }}</p>
          <div class="topic-actions">
            <button class="btn-action"><i class="fas fa-thumbs-up"></i> {{ topic.likes }}</button>
            <button class="btn-action"><i class="fas fa-comment"></i> {{ topic.comments }}</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'

interface Topic {
  id: number
  title: string
  author: string
  avatar: string
  timeAgo: string
  description: string
  likes: number
  comments: number
}

const props = defineProps<{
  favorites: Topic[]
}>()

const router = useRouter()

const formatTime = (timeAgo: string) => timeAgo

const goToTopicDetail = (id: number) => {
  router.push({ name: 'PostDetail', params: { id } })
}
</script>

<style scoped>
.post-collect {
  padding: 20px;
}

.topic-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.topic-item {
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 15px;
  display: flex;
  gap: 15px;
  cursor: pointer;
  transition: box-shadow 0.3s ease;
}

.topic-item:hover {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.topic-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.topic-content {
  flex: 1;
}

.topic-info h3 {
  margin: 0 0 10px;
}

.author-time {
  display: flex;
  justify-content: space-between;
  font-size: 0.9em;
  color: #666;
}

.description {
  margin: 10px 0 0;
}

.topic-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.btn-action {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  color: #666;
}

.btn-action:hover {
  color: #42b983;
}
</style>